//
//  ZOrderShipingAddressCell.m
//  DistributorAB
//
//  Created by LZY on 2019/10/11.
//  Copyright © 2019 主事丫环. All rights reserved.
//

#import "ZOrderShipingAddressCell.h"
@interface ZOrderShipingAddressCell ()

@end

@implementation ZOrderShipingAddressCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setupViewAction];
    }
    return self;
}
#pragma mark - 界面布局
- (void)setupViewAction{
    _viewNoneAddress = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, 88)];
    _viewNoneAddress.backgroundColor = kColorWithHex(0xffffff);
    _viewNoneAddress.hidden = NO;
    [self.contentView addSubview:_viewNoneAddress];
    
    UIImageView *ivAddress = [[UIImageView alloc] initWithFrame:CGRectMake((kScreen_Width - 38) / 2.0, 16, 38, 36)];
    ivAddress.image = imgname(@"user_address_none_default_icon");
    [_viewNoneAddress addSubview:ivAddress];
    
    UILabel *lblNotice = [[UILabel alloc] initWithFrame:CGRectMake(0, 58, kScreen_Width, 14)];
    lblNotice.text = @"请添加收获地址";
    lblNotice.font = [UIFont systemFontOfSize:14];
    lblNotice.textColor = kColorWithHex(0x666666);
    lblNotice.textAlignment = NSTextAlignmentCenter;
    [_viewNoneAddress addSubview:lblNotice];
    
    UIImageView *ivArrow = [[UIImageView alloc] initWithFrame:CGRectMake(kScreen_Width - 23, 48, 8, 16)];
    ivArrow.image = imgname(@"arrow_right_icon");
    [_viewNoneAddress addSubview:ivArrow];
    
    
    _viewAddress = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, 88)];
    _viewAddress.backgroundColor = kColorWithHex(0xffffff);
    _viewAddress.hidden = YES;
    [self.contentView addSubview:_viewAddress];
    
    UILabel *lblNoticeName = [[UILabel alloc] initWithFrame:CGRectMake(16, 12, 70, 19)];
    lblNoticeName.text = @"收件人:";
    lblNoticeName.font = [UIFont systemFontOfSize:14];
    lblNoticeName.textColor = kColorWithHex(0x666666);
    [_viewAddress addSubview:lblNoticeName];
    
    _lblName = [UILabel new];
    _lblName.font = [UIFont systemFontOfSize:14];
    _lblName.textColor = kColorWithHex(0x333333);
    _lblName.preferredMaxLayoutWidth = 150;
    [_viewAddress addSubview:_lblName];
    [_lblName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.viewAddress.mas_top).offset(12);
        make.leading.equalTo(self.viewAddress.mas_leading).offset(88);
        make.height.mas_equalTo(19);
    }];
    
    _lblPhone = [UILabel new];
    _lblPhone.font = [UIFont systemFontOfSize:14];
    _lblPhone.textColor = kColorWithHex(0x333333);
    _lblPhone.textAlignment = NSTextAlignmentRight;
    [_viewAddress addSubview:_lblPhone];
    [_lblPhone mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.viewAddress.mas_top).offset(12);
        make.trailing.equalTo(self.viewAddress.mas_trailing).offset(-47);
        make.height.mas_equalTo(19);
    }];
    
    UILabel *lblNoticeAddress = [[UILabel alloc] initWithFrame:CGRectMake(16, 36, 70, 19)];
    lblNoticeAddress.text = @"收货地址:";
    lblNoticeAddress.font = [UIFont systemFontOfSize:14];
    lblNoticeAddress.textColor = kColorWithHex(0x666666);
    [_viewAddress addSubview:lblNoticeAddress];
    
    _lblAddress = [UILabel new];
    _lblAddress.font = [UIFont systemFontOfSize:14];
    _lblAddress.textColor = kColorWithHex(0x666666);
    _lblAddress.lineBreakMode = NSLineBreakByCharWrapping;
    _lblAddress.numberOfLines = 0;
    [_viewAddress addSubview:_lblAddress];
    [_lblAddress mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lblNoticeAddress.mas_top);
        make.leading.equalTo(self.lblName.mas_leading);
        make.trailing.equalTo(self.lblPhone.mas_trailing);
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-10);
    }];
    
    UIImageView *ivArrowTwo = [UIImageView new];
    ivArrowTwo.image = imgname(@"arrow_right_icon");
    [_viewAddress addSubview:ivArrowTwo];
    [ivArrowTwo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.lblAddress.mas_top);
        make.trailing.equalTo(self.viewAddress.mas_trailing).offset(-15);
        make.size.mas_equalTo(CGSizeMake(8, 16));
    }];
    
}
#pragma mark - 更新数据
- (void)setShipingAddressModel:(ZMyAddressModel *)shipingAddressModel{
    if (shipingAddressModel) {
        _shipingAddressModel = shipingAddressModel;
        [self updateViewData];
    }
}
#pragma mark - 更新界面内容
- (void)updateViewData{
    if (self.shipingAddressModel.address.length > 0) {
        self.viewNoneAddress.hidden = YES;
        self.viewAddress.hidden = NO;
        self.lblName.text = self.shipingAddressModel.user_name;
        self.lblPhone.text = self.shipingAddressModel.phone;
        self.lblAddress.text = [self.shipingAddressModel.address stringByReplacingOccurrencesOfString:@" " withString:@""];
    }else{
        self.viewNoneAddress.hidden = NO;
        self.viewAddress.hidden = YES;
    }
}
+ (CGFloat)cellHeight{
    return 88.0;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
